//
//  IdCardAuthSuccessContentView.swift
//  身份信息认证 - 成功
//
//  Created by 千策万划-mini on 2025/5/6.
//

import Foundation

class IdCardAuthSuccessContentView: UIView {
    
    // MARK: - lazy
    lazy var imageTop: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "icon_idcard_success_top")
        result.widthHeight = XY(W(184), W(166))
        result.centerXTop = XY(SCREEN_WIDTH/2, W(33))
        return result
    }()
    lazy var imageBack: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "icon_idcard_confirm_info_bg")
        result.widthHeight = XY(SCREEN_WIDTH-W(15)*2, (SCREEN_WIDTH-W(15)*2)/825*873)
        return result
    }()
    // 名字
    lazy var labelNameTitle: UILabel = {
        let result = UILabel()
        result.textColor = COLOR_LABEL()
        result.font = UIFont.customSemiBoldFont(size: 16)
        result.fitTitle("Full Name", variable: 0)
        return result
    }()
    lazy var imageNameBg: UIButton = {
        let result = UIButton()
        result.setBackgroundImage(UIImage(named: "icon_login_agree_bg"), for: .normal)
        return result
    }()
    lazy var labelName: OutlineLabel = {
        let result = OutlineLabel()
        return result
    }()
    lazy var imageNameState: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "icon_agree_check")
        result.widthHeight = XY(W(24), W(24))
        return result
    }()
    
    // 身份证号码
    lazy var labelNumberTitle: UILabel = {
        let result = UILabel()
        result.textColor = COLOR_LABEL()
        result.font = UIFont.customSemiBoldFont(size: 16)
        result.fitTitle("ID NO.", variable: 0)
        return result
    }()
    lazy var imageNumberBg: UIButton = {
        let result = UIButton()
        result.setBackgroundImage(UIImage(named: "icon_login_agree_bg"), for: .normal)
        return result
    }()
    lazy var labelNumber: OutlineLabel = {
        let result = OutlineLabel()
        return result
    }()
    lazy var imageNumberState: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "icon_agree_check")
        result.widthHeight = XY(W(24), W(24))
        return result
    }()
    
    // 生日
    lazy var labelTimeTitle: UILabel = {
        let result = UILabel()
        result.textColor = COLOR_LABEL()
        result.font = UIFont.customSemiBoldFont(size: 16)
        result.fitTitle("Date of Birth", variable: 0)
        return result
    }()
    lazy var imageTimeBg: UIButton = {
        let result = UIButton()
        result.setBackgroundImage(UIImage(named: "icon_login_agree_bg"), for: .normal)
        return result
    }()
    lazy var labelBirth: OutlineLabel = {
        let result = OutlineLabel()
        return result
    }()
    lazy var imageBirthState: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "icon_agree_check")
        result.widthHeight = XY(W(24), W(24))
        return result
    }()
    
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.widthHeight = XY(SCREEN_WIDTH, 0)
        self.backgroundColor = .clear
        self.addSubView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 添加
    func addSubView() {
        addSubview(imageBack)
        addSubview(imageTop)
        
        imageBack.addSubview(labelNameTitle)
        imageBack.addSubview(imageNameBg)
        imageNameBg.addSubview(labelName)
        imageNameBg.addSubview(imageNameState)
        
        imageBack.addSubview(labelNumberTitle)
        imageBack.addSubview(imageNumberBg)
        imageNumberBg.addSubview(labelNumber)
        imageNumberBg.addSubview(imageNumberState)
        
        imageBack.addSubview(labelTimeTitle)
        imageBack.addSubview(imageTimeBg)
        imageTimeBg.addSubview(labelBirth)
        imageTimeBg.addSubview(imageBirthState)
        
        resetView()
    }
    
    
    // MARK: - 重置界面
    func resetView(name: String = "", number: String = "", birth: String = "") {
        imageBack.centerXTop = XY(SCREEN_WIDTH/2, imageTop.bottom-W(25))
        
        let widthItem = imageBack.width-labelNameTitle.left*2
        // 姓名
        labelNameTitle.leftTop = XY(W(20), W(53))
        imageNameBg.widthHeight = XY(widthItem, widthItem/305*48)
        imageNameBg.leftTop = XY(labelNameTitle.left, labelNameTitle.bottom+W(10))
        if isStr(name) {
            labelName.resetView(
                title: name,
                textColor: COLOR_WHITE(),
                font: UIFont.customBoldFont(size: 14),
                shadowColor: UIColor(hex: "#2D0084"),
                outlineColor: UIColor(hex: "#2D0084")
            )
            labelName.leftCenterY = XY(W(12), imageNameBg.height/2)
        }
        imageNameState.rightTop = XY(imageNameBg.width, 0)
        
        // 身份证号码
        labelNumberTitle.leftTop = XY(labelNameTitle.left, imageNameBg.bottom+W(16))
        imageNumberBg.widthHeight = imageNameBg.widthHeight
        imageNumberBg.leftTop = XY(labelNameTitle.left, labelNumberTitle.bottom+W(10))
        if isStr(number) {
            labelNumber.resetView(
                title: number,
                textColor: COLOR_WHITE(),
                font: UIFont.customBoldFont(size: 14),
                shadowColor: UIColor(hex: "#2D0084"),
                outlineColor: UIColor(hex: "#2D0084")
            )
            labelNumber.leftCenterY = XY(W(12), imageNameBg.height/2)
        }
        imageNumberState.rightTop = XY(imageNumberBg.width, 0)
        
        // 生日
        labelTimeTitle.leftTop = XY(labelNameTitle.left, imageNumberBg.bottom+W(16))
        imageTimeBg.widthHeight = imageNameBg.widthHeight
        imageTimeBg.leftTop = XY(labelNameTitle.left, labelTimeTitle.bottom+W(10))
        if isStr(birth) {
            labelBirth.resetView(
                title: birth,
                textColor: COLOR_WHITE(),
                font: UIFont.customBoldFont(size: 14),
                shadowColor: UIColor(hex: "#2D0084"),
                outlineColor: UIColor(hex: "#2D0084")
            )
            labelBirth.leftCenterY = XY(W(12), imageNameBg.height/2)
        }
        imageBirthState.rightTop = XY(imageTimeBg.width, 0)
        
        height = imageBack.bottom+getBottomSafeAreaHeight()+60
    }
}
